package com.time.admin.common.config;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.event.ApplicationReadyEvent;
import org.springframework.context.event.EventListener;
import org.springframework.stereotype.Component;

/**
 * 配置验证器类
 *
 * @author: HuangQi
 * @date: Created in 18:00 2025/11/14
 * @description: 验证配置类是否正确加载
 */
@Slf4j
@Component
public class ConfigurationValidator {

    @Autowired
    private WebsiteProperties websiteProperties;

    @Autowired
    private EmailProperties emailProperties;

    @Autowired
    private BackupProperties backupProperties;

    @EventListener(ApplicationReadyEvent.class)
    public void validateConfigurations() {
        try {
            log.info("========== 配置加载验证开始 ==========");
            
            // 验证网站配置
            if (websiteProperties != null) {
                log.info("网站配置加载成功: siteName={}", websiteProperties.getSiteName());
            } else {
                log.error("网站配置加载失败");
            }

            // 验证邮件配置
            if (emailProperties != null) {
                log.info("邮件配置加载成功: enabled={}, host={}", 
                    emailProperties.getEnabled(), 
                    emailProperties.getSmtp().getHost());
            } else {
                log.error("邮件配置加载失败");
            }

            // 验证备份配置
            if (backupProperties != null) {
                log.info("备份配置加载成功: enabled={}, frequency={}", 
                    backupProperties.getEnabled(), 
                    backupProperties.getFrequency().name);
            } else {
                log.error("备份配置加载失败");
            }

            log.info("========== 配置加载验证完成 ==========");
        } catch (Exception e) {
            log.error("配置验证过程中发生错误", e);
        }
    }
}
